﻿using System.Security.Cryptography.X509Certificates;

namespace PrimeNumberAfterOptimized
{
    internal class Program
    {
        static void Main(string[] args)
        {
                int PrimeNum = 1;
                Console.WriteLine("Input a num,please:");
                ///输入范围
                int n = int.Parse(Console.ReadLine());
                ///利用循环判断素数
                DateTime BeforeRuning = DateTime.Now;
                bool find = true;
            ///从大到小判断素数，减小判断次数
            for (int i = n; i >= 2; i--)
            {
                for (int j = 2; j <= i; j++)
                {
                    if (i % j == 0)
                        if (j == i)
                            PrimeNum = i;
                        else
                            break;
                }
                if(PrimeNum == i)
                    break;
            }  
                Console.WriteLine("The maximun prime number is:");
                Console.WriteLine(PrimeNum);
                ///计算代码运行时间
                DateTime AfterRuning = DateTime.Now;
                TimeSpan RuningTime = AfterRuning.Subtract(BeforeRuning);
                Console.Write("Runing time:");
                Console.WriteLine(RuningTime);
            }
        }
    }


       
               

                       
               

               
               